//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

namespace EntLibContrib.Resource.Configuration.Design
{
	class ResourceCommandRegistrar : CommandRegistrar
	{
		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="T:ResourceCommandRegistrar"/> class.
		/// </summary>
		/// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public ResourceCommandRegistrar (IServiceProvider serviceProvider) : base(serviceProvider)
		{
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Register the commands.
		/// </summary>
		public override void Register ()
		{
			AddResourceSettingsCommand();
			AddDefaultCommands(typeof(ResourceManagerSettingsNode));

			AddResourceManagerCommand();
			AddDefaultCommands(typeof(ResourceManagerNode));

			AddCustomResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(CustomResourceProviderNode));
			AddDefaultCommands(typeof(CustomResourceProviderNode));

			AddAssemblyResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(AssemblyResourceProviderNode));
			AddDefaultCommands(typeof(AssemblyResourceProviderNode));

			AddBinaryResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(BinaryResourceProviderNode));
			AddDefaultCommands(typeof(BinaryResourceProviderNode));

			AddResXResourceProviderCommand();
			AddGenerateStronglyTypedResourcesCommand(typeof(XmlResourceProviderNode));
			AddDefaultCommands(typeof(XmlResourceProviderNode));
		}
		#endregion

		#region Private Methods
		private void AddResourceSettingsCommand ()
		{
			ConfigurationUICommand cmd = ConfigurationUICommand.CreateSingleUICommand(ServiceProvider, InternalResources.ResourceSettingsUICommandText, InternalResources.ResourceSettingsUICommandLongText, new AddResourceManagerSettingsNodeCommand(ServiceProvider), typeof(ResourceManagerSettingsNode));
			AddUICommand(cmd, typeof(ConfigurationApplicationNode));
		}

		private void AddResourceManagerCommand ()
		{
			AddMultipleChildNodeCommand(InternalResources.ResourceManagerMenuText, InternalResources.ResourceManagerStatusText, typeof(ResourceManagerNode), typeof(ResourceManagerCollectionNode));
		}

		private void AddCustomResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.CustomResourceProviderUICommandText, InternalResources.CustomResourceProviderUICommandLongText, typeof(CustomResourceProviderNode), typeof(ResourceProviderNode), typeof(ResourceManagerNode));
		}

		private void AddAssemblyResourceProviderCommand ()
		{
			AddSingleChildNodeCommand(InternalResources.AssemblyResourceProviderUICommandText, InternalResources.AssemblyResourceProviderUICommandLongText, typeof(AssemblyResourceProviderNode), typeof(ResourceProviderNode), typeof(ResourceManagerNode));
		}

		private void AddBinaryResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.BinaryResourceProviderUICommandText, InternalResources.BinaryResourceProviderUICommandLongText, typeof(BinaryResourceProviderNode), typeof(ResourceProviderNode), typeof(ResourceManagerNode));
		}

		private void AddResXResourceProviderCommand()
		{
			AddSingleChildNodeCommand(InternalResources.XmlResourceProviderUICommandText, InternalResources.XmlResourceProviderUICommandLongText, typeof(XmlResourceProviderNode), typeof(ResourceProviderNode), typeof(ResourceManagerNode));
		}

		private void AddGenerateStronglyTypedResourcesCommand(Type resourceProviderNodeType)
		{
			ConfigurationUICommand command = new ConfigurationUICommand(
				ServiceProvider,
				InternalResources.GenerateStronglyTypedResourcesUICommandText,
				InternalResources.GenerateStronglyTypedResourcesUICommandLongText,
				CommandState.Enabled,
				new GenerateStronglyTypedResourcesNodeCommand(ServiceProvider),
				System.Windows.Forms.Shortcut.None,
				InsertionPoint.Action,
				null);
			AddUICommand(command, resourceProviderNodeType);
			command.Dispose();
		}
		#endregion
	}
}